#include <iostream>
#include <unordered_map>
#include <string>

bool is_prime(int number) {
  if (number <= 1) {
    return false;
  }
  for (int i = 2; i <= static_cast<int>(number * 0.5) + 1; i++) {
    if (number % i == 0) {
      return false;
    }
  }
  return true;
}

int find_nearest_prime(const std::vector<std::string>& number_words) {
  std::unordered_map<std::string, std::string> number_words_to_digits = {
      {"zero", "0"}, {"one", "1"}, {"two", "2"}, {"three", "3"}, {"four", "4"},
      {"five", "5"}, {"six", "6"}, {"seven", "7"}, {"eight", "8"}, {"nine", "9"}
  };
  std::string number_str;
  for (const auto& word : number_words) {
    auto it = number_words_to_digits.find(word);
    if (it != number_words_to_digits.end()) {
      number_str += it->second;
    }
  }
  if (!std::all_of(number_str.begin(), number_str.end(), ::isdigit) || number_str.length() != 3) {
    return -1;
  }
  int number = std::stoi(number_str);
  int lower_number = number - 1;
  int upper_number = number + 1;
  while (true) {
    if (is_prime(lower_number)) {
      return lower_number;
    } else if (is_prime(upper_number)) {
      return upper_number;
    } else {
      lower_number--;
      upper_number++;
    }
  }
}

int main() {
  std::string input;
  std::getline(std::cin, input);
  std::istringstream iss(input);
  std::vector<std::string> number_words;
  std::string word;
  while (iss >> word) {
    number_words.push_back(word);
  }
  int result = find_nearest_prime(number_words);
  if (result == -1) {
    std::cout << "Wrong input" << std::endl;
  } else {
    std::cout << result << std::endl;
  }
  return 0;
}